﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MdcMain.Properties;
using MdcService.Configuration;
using MdcService.Structure.Enum;

namespace MdcMain
{
    public class MachinesViewModel
    {
        public string Name { get; set; }
        public string Id { get; set; }
        public string Type { get; set; }
        public BitmapImage Icon { get; set; }
        public string Path { get; set; }

        public MachinesViewModel(MachineDefinition definition)
        {
            Name = definition.Name;
            Id = definition.Id;
            Type = definition.Type.ToString();
            Path = definition.Path;
            switch (definition.Type)
            {
                case MachineType.Moxa:
                    Icon = BitmapToBitmapImage(Resources.MachinePic4);
                    break;
                case MachineType.Siunmerik:
                    Icon = BitmapToBitmapImage(Resources.MachinePic2);
                    break;
                case MachineType.Testing:
                    Icon = BitmapToBitmapImage(Resources.MachinePic1);
                    break;
            }

        }

        private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
        {
            BitmapImage bitmapImage = new BitmapImage();
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                bitmap.Save(ms, bitmap.RawFormat);
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = ms;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
                bitmapImage.Freeze();
            }
            return bitmapImage;
        }
       
    }
}
